package org.client.otdr.executor;

import java.util.HashMap;
import java.util.Map;

import org.client.otdr.Executor;
import org.client.otdr.OTDRID;
import org.openems.PrimitiveTraceEntity;
import org.openems.entity.Key;
import org.openems.entity.TraceEntity;

import framework.Accessor;
import framework.webclient.RestSocket;
import framework.webclient.SystemProperty;

public class FilelistExecutor implements Executor {

	private Accessor accessor;
	private RestSocket restSocket;
	private SystemProperty systemProperty;
	
	public FilelistExecutor(Accessor accessor, RestSocket restSocket, SystemProperty systemProperty) {
		this.accessor = accessor;
		this.restSocket = restSocket;
		this.systemProperty = systemProperty;
	}

	@Override
	public void execute(Key key) {
		OTDRID id = OTDRID.get();
		Map<String, String> parameters = new HashMap<String, String>();
		parameters.put("key", accessor.get(id.FILELIST).getValueText());
		PrimitiveTraceEntity trace = restSocket.get("otdrFile", PrimitiveTraceEntity.class, parameters);
		TraceEntity traceEntity = (TraceEntity)accessor.get(id.TRACE);
		traceEntity.setData(trace.y.toArray(new Double[0]));
		accessor.put(traceEntity);
	}

}
